# -*- coding:utf-8 -*-
"""可能用到的函数
ord()
chr()
"""


def parse_non_alpha(s: str) -> str:
    """删除字符串中的非字母"""
    return "".join([c for c in s if c.isalpha()])


def parse_non_alnum(s: str) -> str:
    """删除字符中的非字母数字"""
    return "".join([c for c in s if c.isalnum()])


def convert_hex_to_string(s: str) -> str:
    """把一串十六进制字符串按照ASCII码规则转换为ASCII字符串"""
    res = []
    map_hex = map_hex_construct()
    for i in range(0, len(s), 2):
        res.append(map_hex.get(s[i]) * 16 + map_hex.get(s[i + 1]))
    return "".join(chr(c) for c in res)


def map_hex_construct() -> dict:
    """生成一个十六进制字符的对照字典"""
    map_hex = {}
    for i in range(16):
        if i <= 9:
            map_hex[str(i)] = i
        else:
            map_hex[chr(i + 87)] = i
    return map_hex


if __name__ == "__main__":
    print(map_hex_construct())
    print(convert_hex_to_string("61786f"))
